﻿/*
' Copyright (c) 2012-2013 Kyriakos Lesgidis
'  All rights reserved.
' 
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
' DEALINGS IN THE SOFTWARE.
' 
*/

using System;
using DotNetNuke.Services.Exceptions;
using System.Data;
using System.Web.UI.WebControls;
using DotNetNuke.Services.FileSystem;
using DotNetNuke.Common;
using DotNetNuke.Modules.DNNPagination.Components;

namespace DotNetNuke.Modules.DNNPagination
{

    /// -----------------------------------------------------------------------------
    /// <summary>
    /// The EditCameraSlideshow class is used to manage content
    /// 
    /// Typically your edit control would be used to create new content, or edit existing content within your module.
    /// The ControlKey for this control is "Edit", and is defined in the manifest (.dnn) file.
    /// 
    /// Because the control inherits from CameraSlideshowModuleBase you have access to any custom properties
    /// defined there, as well as properties from DNN such as PortalId, ModuleId, TabId, UserId and many more.
    /// 
    /// </summary>
    /// -----------------------------------------------------------------------------
    public partial class EditItem : DNNPaginationModuleBase
    {
        private int itemId;

        #region Event Handlers

        override protected void OnInit(EventArgs e)
        {
            InitializeComponent();
            base.OnInit(e);
        }

        private void InitializeComponent()
        {
            this.Load += new System.EventHandler(this.Page_Load);
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Page_Load runs when the control is loaded
        /// </summary>
        /// -----------------------------------------------------------------------------

        private void Page_Load(object sender, System.EventArgs e)
        {
            try
            {
                itemId = Convert.ToInt32(Request.QueryString["Id"]);
                if (!Page.IsPostBack)
                {                    
                    DataTable dt = new DataTable();
                    dt.Load(cContentController.getContentById(itemId));
                    
                    txtTitle.Text = dt.Rows[0]["DNNPaginationContentTitle"].ToString();
                    teCaption.Text = Server.HtmlDecode(dt.Rows[0]["DNNPaginationContentText"].ToString());
                }
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }

        #endregion                    

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            cContent c = new cContent();
            c.Id = itemId;
            c.Title = txtTitle.Text;
            c.Text = teCaption.Text;
            cContentController.updateContent(c);

            Response.Redirect(Globals.NavigateURL(PortalSettings.ActiveTab.TabID, "Edit", "mid=" + ModuleId, "popUp=true"));
        }

        protected void LinkButton3_Click(object sender, EventArgs e)
        {
            Response.Redirect(Globals.NavigateURL(PortalSettings.ActiveTab.TabID, "Edit", "mid=" + ModuleId, "popUp=true"));
        }

        protected void LinkButton2_Click(object sender, EventArgs e)
        {
            cContentController.deleteContent(Convert.ToInt32(itemId));
            Response.Redirect(Globals.NavigateURL(PortalSettings.ActiveTab.TabID, "Edit", "mid=" + ModuleId, "popUp=true"));
        }
    }

}